﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Ebook : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Calendar.SelectedDate = DateTime.Today;
        if (Convert.ToString(Session["Dangnhap"]) == "")
            Response.Redirect("~/Admin/Login.aspx");

        else
            Response.Write("Xin chào " + Convert.ToString(Session["Dangnhap"]));
    }
    private void SaveFileUpload()
    {
        string strFilename;
        if (FileUpload.FileName != "")
        {
            strFilename = Server.MapPath("~/App_Data/upload/ebook\\" + FileUpload.FileName);
            FileUpload.PostedFile.SaveAs(strFilename);
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Label2.Visible = true;
        //Label3.Visible = true;
        Label4.Visible = true;
        Label5.Visible = true;
        Label6.Visible = true;
        Label7.Visible = true;
        Label8.Visible = true;
        Label9.Visible = true;
        //txtID.Visible = true;
        txtIsbn.Visible = true;
        txtTitle.Visible = true;
        ddlCategoryid.Visible = true;
        ddlUploadid.Visible = true;
        FileUpload.Visible = true;
        Calendar.Visible = true;
        btnEdit.Visible = true;
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        SqlDataSource1.Update();
        SaveFileUpload();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        SqlDataSource1.Delete();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Admin/Add_Ebook.aspx");
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtID.Text = HttpUtility.HtmlDecode(GridView1.Rows[GridView1.SelectedIndex].Cells[1].Text);
        txtIsbn.Text = HttpUtility.HtmlDecode(GridView1.Rows[GridView1.SelectedIndex].Cells[2].Text);
        txtTitle.Text = HttpUtility.HtmlDecode(GridView1.Rows[GridView1.SelectedIndex].Cells[3].Text);
        ddlCategoryid.SelectedValue = HttpUtility.HtmlDecode(GridView1.Rows[GridView1.SelectedIndex].Cells[5].Text);
        ddlUploadid.SelectedValue = HttpUtility.HtmlDecode(GridView1.Rows[GridView1.SelectedIndex].Cells[7].Text);
    }
}
